package org.example.ch10.controller;

import org.example.ch10.service.PublishService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName AdminController
 * @Description TODO
 * @Author Kx
 * @Date 2025/9/21 19:33
 * @Version 1.0
 */
@RestController
public class AdminController {
    private final static Logger log = LoggerFactory.getLogger(AdminController.class);

    private final PublishService publishService;

    public AdminController(PublishService publishService) {
        this.publishService = publishService;
    }

    @PostMapping("/message/{topic}")
    public String send(@PathVariable("topic") String topic, @RequestParam("message") String message) {
        log.info("消息: {}",message);
        publishService.sendMessage(topic, message);
        return "success";
    }
}
